/*!
\copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.\n
            All Rights Reserved.\n
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\brief      The events sent from the mirror profile using the Event Bus
*/

#ifdef INCLUDE_MIRRORING

#include "mirror_profile_send_event.h"
#include "event_bus_publish.h"

#include <logging.h>

#ifdef ENABLE_LEA_CIS_DELEGATION

/*! \brief Send message through Event Bus.

 \param event event bus event to publish.
 \param data data associated with the event
 \param data_size size of the data

 */
static void mirrorProfile_PublishEvent(le_audio_core_event_t event, void * data, uint16 data_size)
{
    EventBus_Publish(EVENT_BUS_CHANNEL_LE_AUDIO_CORE, event, data, data_size);
}

void mirrorProfile_SendCisEstablishedEvent(const MDM_LE_CIS_CREATE_IND_T *uprim)
{
    LE_AUDIO_CORE_CIS_ESTABLISHED_T event = {0};

    event.subevent_code = 0x19;
    event.status = uprim->status;
    event.conHandle = uprim->cis_handle;
    event.cigSyncDelay= uprim->cis_params.cig_sync_delay;
    event.cisSyncDelay= uprim->cis_params.cis_sync_delay;
    event.transportLatencyC2P= uprim->cis_params.transport_latency_c_to_p;
    event.transportLatencyP2C= uprim->cis_params.transport_latency_p_to_c;
    event.phyC2P= uprim->cis_params.phy_c_to_p;
    event.phyP2C= uprim->cis_params.phy_p_to_c;
    event.nse= uprim->cis_params.nse;
    event.bnC2P= uprim->cis_params.bn_c_to_p;
    event.bnP2C= uprim->cis_params.bn_p_to_c;
    event.ftC2P= uprim->cis_params.ft_c_to_p;
    event.ftP2C= uprim->cis_params.ft_p_to_c;
    event.maxPduC2P= uprim->cis_params.max_pdu_c_to_p;
    event.maxPduP2C= uprim->cis_params.max_pdu_p_to_c;
    event.isoInterval= uprim->cis_params.iso_interval;

    mirrorProfile_PublishEvent(le_audio_core_cis_established, &event, sizeof(LE_AUDIO_CORE_CIS_ESTABLISHED_T));
}

void mirrorProfile_SendCisDisconnectedEvent(const MDM_LE_CIS_DISCONNECT_IND_T *uprim)
{
    LE_AUDIO_CORE_CIS_DISCONNECTION_COMPLETE_T event = {0};

    event.status = hci_success;
    event.connection_handle = uprim->conn_handle;
    event.reason = uprim->reason;
    event.type = cis_link;

    mirrorProfile_PublishEvent(le_audio_core_cis_disconnection_complete, &event, sizeof(LE_AUDIO_CORE_CIS_ESTABLISHED_T));
}

#endif /* ENABLE_LEA_CIS_DELEGATION */

#endif /* INCLUDE_MIRRORING */
